package com.bsoft.gol.hcs.task;

import com.bsoft.gol.hcs.enumcase.InterfaceTypeEnum;
import com.bsoft.gol.hcs.his.bean.request.PushMessageRequest;
import com.bsoft.gol.hcs.his.bean.request.SendMsgRequest;
import com.bsoft.gol.hcs.his.bean.vo.MsgVariable;
import com.bsoft.gol.hcs.his.service.SendMsgService;
import hcn.bean.specialist.vo.SatisfactionDoctorPushVo;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class SatisfactionDoctorPushThread extends Thread {
    private SatisfactionDoctorPushVo satisfactionDoctor;
    private SendMsgRequest sendMsgRequest;
    private int type;
    private SendMsgService sendMsgService;
    private String userId;
    private String content;
    private int mins;

    public SatisfactionDoctorPushThread(SatisfactionDoctorPushVo satisfactionDoctor, SendMsgRequest sendMsgRequest, SendMsgService sendMsgService, String userId, String content, int mins, int type) {
        this.satisfactionDoctor = satisfactionDoctor;
        this.sendMsgRequest = sendMsgRequest;
        this.type = type;
        this.sendMsgService = sendMsgService;
        this.userId = userId;
        this.content = content;
        this.mins = mins;
    }

    @Override
    public void run() {
        List<MsgVariable> msgVariableList = new ArrayList<>();
        if (InterfaceTypeEnum.HOL.getCode().equals(sendMsgRequest.getType())) {
            //互联网医院的推送
            sendMsgRequest.setUserType(2);
            if (1 == type) {
                //发起处理推送给医生所在部门的医生
                sendMsgRequest.setBusinessType(234);
                MsgVariable msgVariable = new MsgVariable();
                msgVariable.setMsgVariableKey("【医生名称】");
                msgVariable.setMsgVariableValue(satisfactionDoctor.getDoctorName());
                msgVariableList.add(msgVariable);
                MsgVariable msgVariable1 = new MsgVariable();
                msgVariable1.setMsgVariableKey("doctorId");
                msgVariable1.setMsgVariableValue(satisfactionDoctor.getDoctorId());
                msgVariableList.add(msgVariable1);
                sendMsgRequest.setMsgVariableList(msgVariableList);
                sendMsgService.productionMessage(sendMsgRequest);

            }
        } else if (InterfaceTypeEnum.GOL.getCode().equals(sendMsgRequest.getType())) {
            //健康通推送
            if (1 == type) {
                //发起处理推送给医生所在部门的医生
                PushMessageRequest pushMessageRequest= new PushMessageRequest();
                pushMessageRequest.setTemplateCode("SATISFACTION_SURVEY");
                pushMessageRequest.setNotificateType("satisfaction_survey");
                pushMessageRequest.setRoleId("doctor");
                pushMessageRequest.setUserId(userId);
                Map<String, String>  variableMap=new HashMap<>();
                variableMap.put("jiguang","极光消息");
                variableMap.put("#医生姓名#",satisfactionDoctor.getDoctorName());
                pushMessageRequest.setMsgVariableMap(variableMap);

                Map<String,String> extraMap = new HashMap<>();
                extraMap.put("doctorId", satisfactionDoctor.getDoctorId());
                extraMap.put("doctorName", satisfactionDoctor.getDoctorName());
                pushMessageRequest.setExtras(extraMap);
                sendMsgService.pushNewMessage(pushMessageRequest);
            }
        }

    }
}